<%--
  @author Supun Viraj Rathnayaka
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/dateSelector.js"></script>
<script src="${pageContext.request.contextPath}/js/printer.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/js/validateLand.js" type="text/javascript"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/jquery.jqplot.css"/>
<script type="text/javascript" src="${pageContext.request.contextPath}/lib/jqplot/jquery.jqplot.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/lib/jqplot/jqplot.pieRenderer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/lib/jqplot/jqplot.barRenderer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/lib/jqplot/jqplot.categoryAxisRenderer.js"></script>


<script type="text/javascript">

$(function(){
    $('select#railwayTrackId').bind('change', function (evt1) {
        var id = $("select#railwayTrackId").attr("value");
        if(id>0){
            $.getJSON('${pageContext.request.contextPath}/common/DivisionLookupService', {id: id, mode: 6},
                    function (data) {
                        var options1 = '<option value="0">' + $('#all').val() + '</option> ';
                        var ds = data.districtList;
                        for (var i = 0; i < ds.length; i++) {
                            options1 += '<option value="' + ds[i].optionValue + '">' + ds[i].optionDisplay + '</option>'
                        }
                        $("select#districtId").html(options1);
                    });
        }else{
            $("select#districtId").html('<option value="0">' + $('#all').val() + '</option> ');
        }
    });
});

function getAgeAnalysisData(){
    var branchId = $('select#branchId').attr("value");
    var trackId = $('select#railwayTrackId').attr("value");
    var districtId = $('select#districtId').attr("value");
    var years = $('select#yearsBackId').attr("value");
    var type = "AgeAnalysis";

    $.getJSON('${pageContext.request.contextPath}/common/RailwayReportService', {type: type, branch: branchId, track: trackId, district: districtId, years: years},function (data) {
        loadLandList(data.landList);
    });
}
</script>

<div id="land-registration-module-home-title" class="module-home-title">
    <s:a href="reportModule.do">
        <span><img src="${pageContext.request.contextPath}/images/print.png" alt="Print">
            <s:label value="%{getText('reports.label')}"/></span>
    </s:a>
    <span class="module-title-breaker"> > </span>
    <s:a href="leaseDetailsReport.do">
        <span><img src="${pageContext.request.contextPath}/images/list.png" alt="">
            <s:label value="Arrears Age Analysis"/></span>
    </s:a>
    <div id="back-button" align="right">
        <s:form><s:submit value="%{getText('back_btn.label')}" action="reportModule"/></s:form>
    </div>
</div>

<div id="printbtn" class="form-button-div right-align">
    <input type="button" style="margin:10" id="printBtnId" value="Print" onclick="printPage('init-land-report-list', 'A4', 'P');"/>
</div>

<div id="init-land-report-list">
    <div class="page-title center-align">
        <h2><s:label value="Arrears Age Analysis Report"/></h2>
    </div>
    <s:form action="genArrearsAgeAnalysis.do">
        <table class="width-635-px margin-10-auto" id="filter-lists">
            <tr>
                <td colspan="2" class="left-align"><s:label value="%{getText('branch.label')}"/></td>
            </tr>
            <tr>
                <td colspan="2" class="center-align">
                    <s:if test="%{branchList.size==1}">
                        <s:select id="branchId" name="branchId" list="branchList" cssClass="width-250-px"/>
                    </s:if>
                    <s:else>
                        <s:select id="branchId" name="branchId" list="branchList" headerKey="0"
                                  headerValue="%{getText('all.label')}" cssClass="width-250-px"/>
                    </s:else>
                </td>
                <%--<td>--%>
                    <%--<s:select id="landState" name="landState"--%>
                              <%--list="landStateList" headerKey="0"--%>
                              <%--headerValue="%{getText('all.label')}" cssClass="width-200-px"/>--%>
                <%--</td>--%>
            </tr>

            <tr>
                <td><s:label value="%{getText('railway_line.label')}"/></td>
                <td><s:label value="%{getText('district.label')}"/></td>
            </tr>
            <tr>
                <td class="center-align">
                    <s:select id="railwayTrackId" name="railwayTrackId" list="railwayTrackList" headerKey="0"
                              headerValue="%{getText('all.label')}" cssClass="width-250-px"/>
                </td>
                <td class="center-align">
                    <select id="districtId" name="districtName" class="width-250-px"><option value="0"><s:property value="%{getText('all.label')}"/></option></select>
                    <%--<s:if test="%{districtList.size==1}">--%>
                        <%--<s:select id="districtId" name="districtId" list="districtList" cssClass="width-250-px"/>--%>
                    <%--</s:if>--%>
                    <%--<s:else>--%>
                        <%--<s:select id="districtId" name="districtId" list="districtList" headerKey="0"--%>
                                  <%--headerValue="%{getText('all.label')}" cssClass="width-250-px"/>--%>
                    <%--</s:else>--%>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="left-align">
                    <s:label value="Arrears History"/>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="left-align">
                    <s:select id="yearsBackId" name="yearsBackId" list="#@java.util.HashMap@{'1':'1','2':'2','3':'3','4':'4','5':'5'}"
                            cssClass="width-80-px"/><s:label value="Years"/>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="right-align"><s:submit value="%{getText('search.label')}"/></td>
            </tr>
        </table>
    </s:form>


<s:if test="arrearsRecordList != null">
    <s:if test="arrearsRecordList.size() > 0">
        <table class="width-100 margin-10-auto table land-table" id="land-application-form-list" border="1"
               cellpadding="0"
               cellspacing="0">
            <thead>
            <th><s:label value="%{getText('file_no.label')}"/></th>
            <th><s:label value="%{getText('lease_no.label')}"/></th>
            <th><s:label value="More than %{yearsBackId} Years"/></th>
            <s:iterator value="reportYearsList">
                <th><s:property/></th>
            </s:iterator>
            <th><s:label value="Total"/></th>
            </thead>
            <s:iterator status="status1" value="arrearsRecordList">
                <tr>
                    <td class="center-align"><s:property value="fileNo"/></td>
                    <td class="center-align"><s:property value="leaseNo"/></td>
                    <td class="center-align"><s:property value="subTotalArrears"/></td>
                    <s:iterator status="thStatus" value="arrearsRecords">
                        <td><s:property value="value"/></td>
                    </s:iterator>
                    <td class="center-align"><s:property value="totalArrears"/></td>
                </tr>
            </s:iterator>
        </table>
    </s:if>
</s:if>
</div>

<s:hidden id="all" value="%{getText('all.label')}"/>